package organiser;



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Home implements ActionListener, Runnable {
    private JPanel cards = new JPanel(new CardLayout());
    private JFrame homeFrame = new JFrame("FamilyOrganiser v0.1");
    private JPanel homePanel = new JPanel();
    private JButton calendarBtn = new JButton();
    private JButton listBtn = new JButton();
    private JButton postBtn = new JButton();
    private Keyboard keyboard = new Keyboard(this);
    private Postit postIt = new Postit(this, keyboard);
    private CardLayout cl;
    private MysqlDB sql = new MysqlDB();

    public Home(){
        homeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        homeFrame.setVisible(true);
        homeFrame.setSize(800, 480);
        homeFrame.setResizable(false);
        homePanel.setLayout(null);

        calendarBtn.setBounds(80, 200, 200, 100);
        listBtn.setBounds(300, 200, 200, 100);
        postBtn.setBounds(520, 200, 200, 100);
        calendarBtn.addActionListener(this);
        listBtn.addActionListener(this);
        postBtn.addActionListener(this);

        homePanel.add(calendarBtn);
        homePanel.add(listBtn);
        homePanel.add(postBtn);

        cards.add(homePanel, "Home");
        cards.add(keyboard.getJPanel(), "Keyboard");
        cards.add(postIt.getJPanel(), "PostIt");
        homeFrame.add(cards, BorderLayout.CENTER);
        cl = (CardLayout) (cards.getLayout());
        cl.show(cards, "Home");
    }

    public JPanel getCards() {
        return cards;
    }

    public static void main(String[] args) {
        new Thread(new Home()).start();
    }

    public String getDate() { // metoden returnerar den aktuella datum
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat tid = new SimpleDateFormat("dd / MM / yyyy");
        return tid.format(cal.getTime());
    }

    public void actionPerformed(ActionEvent e) {
        Object o = e.getSource();
        if(o == calendarBtn){

        }
        else if(o == listBtn){

        }
        else if(o == postBtn){
            cl.show(cards, "PostIt");
        }
    }

    public void run() { // metoden fÃ¶r att hÃ¥lla reda pÃ¥ klockan
        while (true) {
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
            keyboard.setClock(sdf.format((cal.getTime())));
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ex) {
            }
        }
    }
}
